package com.campus.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.campus.entry.SysUser;
import com.campus.pojo.dto.SysUserDto;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {
    @Insert("insert into t_sys_user_role(user_id, role_id) values (#{userId},(select id from t_sys_role where name =#{role}))")
    void insertRole(@Param("userId") Integer userId, @Param("role") String role);
    @Select("select id from t_sys_user where login_name=#{loginName}")
    Integer getUserIdByLoginName(@Param("loginName") String loginName);
    @Select("select name from t_sys_role where id=" +
            "(select role_id from t_sys_user_role where user_id=#{id})")
    String getRoleById(@Param("id")Integer id);
    @Select("select ur.id ,login_name AS loginName ,password,email,r.name AS  role,status " +
            "from t_sys_user u,t_sys_user_role ur,t_sys_role r" +
            " where u.id=ur.user_id and ur.role_id=r.id and u.status='1'")
    List<SysUserDto> listSysUer();
    @Update("update t_sys_user set status=#{status} where id=#{id}")
    void updateStatus (@Param("status") String status,@Param("id") Integer id);

}
